package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark72Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark72 extends BaseMark {

    LayoutWatermark72Binding binding;

    public Mark72(@NonNull Context context) {
        super(context);
    }

    public Mark72(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark72(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark72Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            hideView(binding.bottom);
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark72Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "owner72", binding.title);
        setText(binding.binding2, "time72", binding.binding2);
        setTime(binding.binding2, new SimpleDateFormat("yyyy/MM/dd HH:mm"));

        setText(binding.binding5, "visit72", binding.binding4);
        setText(binding.binding7, "addr72", binding.binding6);
        setText(binding.binding9, "phone72", binding.binding8);

        setText(binding.binding11, "result72", binding.binding10);
        setText(binding.binding13, "didian72", binding.binding12);
        setText(binding.binding15, "unit72", binding.binding14);
        setText(binding.binding17, "xiaoqu72", binding.binding16);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("owner72", "业主名称"));
        list.add(new EditItem("time72", "时间", true));
        list.add(new EditItem("visit72", "拜访人"));
        list.add(new EditItem("addr72", "客户住址"));
        list.add(new EditItem("phone72", "联系电话"));

        list.add(new EditItem("result72", "拜访总结"));
        list.add(new EditItem("didian72", "地点"));

        list.add(new EditItem("unit72", "物业单位"));
        list.add(new EditItem("xiaoqu72", "小区名称"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding2, new SimpleDateFormat("yyyy/MM/dd HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
